<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>晴天医诊</title>
        <meta name="description" content="晴天医诊">
        <meta name="keywords" content="晴天医诊">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
            .el-dropdown-link {
                cursor: pointer;
                color: #409EFF;
            }
            .el-icon-arrow-down {
                font-size: 12px;
            }

        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>套餐管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>套餐管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="预约人/电话号码" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="handleCurrentChange(1)" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="left"  width="100" label="序号"></el-table-column>
                        <el-table-column prop="member.name" label="预约人"  align="left"  width="100"></el-table-column>
                        <el-table-column prop="member.phonenumber" label="电话号码" align="left"  width="100"></el-table-column>
                        <el-table-column label="适用性别"  align="left"  width="100">
                            <template slot-scope="scope">
                                <span>{{ scope.row.member.sex == '0' ? '不限' : scope.row.member.sex == '1' ? '男' : '女'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="setmeal.name"  label="预约套餐" align="left"></el-table-column>
                        <el-table-column prop="orderdate"  label="预约时间" align="left" :formatter="formatDate"></el-table-column>
                        <el-table-column prop="ordertype" label="预约类型" align="left" ></el-table-column>
                        <el-table-column prop="orderstatus" label="状态" align="left"></el-table-column>

                        <el-table-column label="操作" width="160" align="left">
                            <template slot-scope="scope">
                                <el-button v-if="scope.row.orderstatus=='未到诊'" type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button v-else disabled type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button v-if="scope.row.orderstatus=='未到诊'" size="mini" type="danger" @click="handleDelete(scope.row)">已到诊</el-button>
                                <el-button v-else disabled size="mini" type="danger" @click="handleDelete(scope.row)">已到诊</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增订单" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约人">
                                                        <el-input v-model="formData.name" id="name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="电话">
                                                        <el-input v-model="formData.phonenumber" id="phonenumber"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证">
                                                        <el-input v-model="formData.idcard" id="idcard"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="email">
                                                        <el-input v-model="formData.email"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约日期">
                                                        <el-dropdown @command="handleCommand">
                                                            <span class="el-dropdown-link">
                                                                预约日期<i class="el-icon-arrow-down el-icon--right"></i>
                                                            </span>
                                                            <el-dropdown-menu slot="dropdown">
                                                                <el-dropdown-item :command=o v-for="o in OrderDateList">{{o}}</el-dropdown-item>
                                                            </el-dropdown-menu>
                                                        </el-dropdown>

                                                        {{OrderDateValue}}

                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="说明">
                                                        <el-input v-model="formData.remark" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐</th>
                                                    <th>适用年龄</th>
                                                    <th>适用性别</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="s in tableData">
                                                    <td>
                                                        <input :id="s.id" v-model="SetmealId" type="checkbox" :value="s.id">
                                                    </td>
                                                    <td><label :for="s.id">{{s.name}}</label></td>
                                                    <td><label :for="s.id">{{s.age}}</label></td>
                                                    <td><label :for="s.id">{{ s.sex == '0' ? '不限' : s.sex == '1' ? '男' : '女'}}
                                                    </label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑订单" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约人">
                                                        <el-input v-model="formData.name" id="name1"/>
                                                        <el-input v-model="formData.id" />
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="电话">
                                                        <el-input v-model="formData.phonenumber"  :disabled="true"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证">
                                                        <el-input v-model="formData.idcard" id="idcard1"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="email">
                                                        <el-input v-model="formData.email"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约日期">
                                                        <el-dropdown @command="handleCommand">
                                                            <span class="el-dropdown-link">
                                                                预约日期<i class="el-icon-arrow-down el-icon--right"></i>
                                                            </span>
                                                            <el-dropdown-menu slot="dropdown">
                                                                <el-dropdown-item :command=o v-for="o in OrderDateList">{{o}}</el-dropdown-item>
                                                            </el-dropdown-menu>
                                                        </el-dropdown>

                                                        {{OrderDateValue}}

                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="套餐">
                                                        <el-select v-model="SetmealId" placeholder="请选择套餐" @change="changes">
                                                            <el-option v-for="item in tableData" :key="item.id"
                                                                       :label="item.name" :value="item.id"/>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="说明">
                                                        <el-input v-model="formData.remark" type="textarea" ></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <!--<el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐</th>
                                                    <th>适用年龄</th>
                                                    <th>适用性别</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                    <tr v-for="s in tableData">
                                                        <td>
                                                            <input :id="s.id" v-model="SetmealId" type="checkbox" :value="s.id">
                                                        </td>
                                                        <td><label :for="s.id">{{s.name}}</label></td>
                                                        <td><label :for="s.id">{{s.age}}</label></td>
                                                        <td><label :for="s.id">{{ s.sex == '0' ? '不限' : s.sex == '1' ? '男' : '女'}}
                                                        </label></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>-->
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                OrderDateList:null,
                OrderDateValue:null,
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null//查询条件
				},
				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                tableData:[],//添加表单窗口中检查组列表数据
                SetmealId:[],//添加表单窗口中套餐组复选框对应id
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit:false,//编辑表单是否可见
                rowid:null,
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                changes(val){
                    // alert(val);
                }
                ,
                //编辑
                handleEdit() {
                    //只要电话号码不能修改
                    if(this.OrderDateValue==null){//如果日期等于空就让它选择一个日期
                        this.$message.error("请选择一个预约日期");
                        return
                    }
                    if(!$('#name1').val()){
                        this.$message.error("请填写预约人");
                        return
                    }
                    /*var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                      if(!reg.test($('#idcard1').val())){
                          this.$message.error("身份证格式不正确");
                          return
                      }*/
                    axios.post("/order/update.do?SetmealId=" + this.SetmealId + "&OrderDateValue=" + this.OrderDateValue+"&id="+this.rowid, this.formData).then(res => {
                        if (res.data.flag) {//成功了
                            this.$message({
                                message: res.data.message,//弹出添加成功消息
                                type: 'success'
                            });
                            this.dialogFormVisible4Edit = false;//提交后隐藏添加标签弹层
                            this.findPage();//刷新数据
                        } else {
                            this.$message.error(res.data.message);//弹出添加失败消息
                        }
                    });





                },
                //添加
                handleAdd () {
                    if(this.OrderDateValue==null){//如果日期等于空就让它选择一个日期
                        this.$message.error("请选择一个预约日期");
                        return
                    }
                    if(!$('#name').val()){
                        this.$message.error("请填写预约人");
                        return
                    }
                    var reg= /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                    if(!reg.test($('#phonenumber').val())){
                        this.$message.error("电话号码格式不正确");
                        return
                    }
                    /*var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    if(!reg.test($('#idcard').val())){
                        this.$message.error("身份证格式不正确");
                        return
                    }*/
                    axios.post("/order/add.do?SetmealId=" + this.SetmealId + "&OrderDateValue=" + this.OrderDateValue, this.formData).then(res => {
                        if (res.data.flag) {//成功了
                            this.$message({
                                message: res.data.message,//弹出添加成功消息
                                type: 'success'
                            });
                            this.dialogFormVisible = false;//提交后隐藏添加标签弹层
                            this.findPage();//刷新数据
                        } else {
                            this.$message.error(res.data.message);//弹出添加失败消息
                        }
                    });

                },
                //分页查询
                findPage() {
                    axios.post("/order/queryPage.do",this.pagination).then(res=>{
                        if(res.data.flag){
                            this.dataList=res.data.data.rows;//返回数据赋值给dataList
                            this.pagination.total=res.data.data.total;//返回数据赋值给dataList
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })
                },
                // 重置表单
                resetForm() {
                    //清空表单数据
                    this.formData={}
                    //清空选中项
                    this.SetmealId=[]
                    this.activeName='first'; //选中基本信息标签项
                    this.OrderDateValue=null
                    this.rowid=null
                },
                // 弹出添加窗口
                handleCreate() {
                    this.resetForm();
                    this.dialogFormVisible=true;
                    //获取检查组列表
                    axios.post("/setmeal/findAll.do").then(res=>{
                        if(res.data.flag){
                            this.tableData=res.data.data;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })
                    //获取体检日期
                    axios.post("/orderSetting/selectByDate.do").then(res=>{
                        console.log(res.data.data)
                        if(res.data.flag){
                            this.OrderDateList=res.data.data;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })

                },
                handleCommand(command) {
                    this.OrderDateValue=command//获取当前选中的父名称
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    this.resetForm();
                    this.rowid=row.id;
                    this.dialogFormVisible4Edit=true;
                    //拿到订单的
                    //获取检查组列表
                    axios.post("/setmeal/findAll.do").then(res=>{
                        if(res.data.flag){
                            this.tableData=res.data.data;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })
                    //获取体检日期
                    axios.post("/orderSetting/selectByDate.do").then(res=>{
                        console.log(res.data.data)
                        if(res.data.flag){
                            this.OrderDateList=res.data.data;
                        }else{
                            this.$message.error(res.data.message);
                        }
                    })

                    axios.post("/order/queryById.do", row).then((res)=>{
                        if(res.data.flag){
                            //打开编辑窗口
                            this.dialogFormVisible4Edit = true;
                            //绑定数据
                            this.formData = res.data.data.member;
                            //绑定套餐id
                            this.SetmealId=res.data.data.setMealId;
                            //绑定体检日期
                            this.OrderDateValue=res.data.data.orderdateValue;

                        }else{
                            this.$message.error("获取数据失败，请刷新当前页面");
                        }
                    });

                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    console.log(row.id)
                    this.$confirm('是否已到诊, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {//确定
                        axios.post("/order/updateStatus.do?id="+row.id).then(res=>{
                            if (res.data.flag){
                                this.$message({
                                    message: res.data.message,//弹出编辑成功消息
                                    type: 'success'
                                });
                                this.findPage();//刷新数据
                            }else{
                                this.$message.error(res.data.message);//弹出删除失败消息
                            }
                        })
                    }).catch(() => {//取消
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                },
                formatDate(row, column) {
                    // 获取单元格数据
                    let data = row[column.property]
                    if(data == null) {
                        return null
                    }
                    let dt = new Date(data)
                    return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
                    /*return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds()*/
                },
            }
        })
    </script>
</html>
